#define _CRT_SECURE_NO_WARNINGS 1
#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <list>
#include <string>
#include <cmath>
#include <bitset>

//#define  x first
//#define  y second

typedef long long ll;
typedef pair<int,int> pir;
bool cmp(pair<int,int>&a, pair<int,int> &b) {
	return a.first < b.second;
}
int main() {

	int n; cin >> n;
	vector<pair<int, int>>city(n);
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		city[i] = { b,a };
	}
	sort(city.begin(), city.end(), cmp);
	int dp[5050];
	for (int i = 0; i < n; i++) {
		dp[i] = 1;
		for (int j = 0; j < i; j++) {
			if (city[i].second > city[j].second)
				dp[i] = max(dp[i], dp[j] + 1);
		}
	}
	int res = 0;
	for (int i = 0; i < n; i++) {
		res = max(res, dp[i]);
	}

	return 0;
}